// Title  router.go
// Description  路由配置
// Author  alittlexincan@163.com  2024/07/22 11:36
// Update  alittlexincan@163.com  2024/07/22 11:36

package router

import (
	"net/http"

	"github.com/gorilla/mux"
	_ "github.com/swaggo/http-swagger/v2"
	exam "xincan.com.cn/tarot-go/internal/app/example/validation/handler"
	user "xincan.com.cn/tarot-go/internal/app/tarot/user/handler"
)

// Router
// Title    		Router
// Description   	系统路由列表配置
// Author      		alittlexincan@163.com         	2024/07/22 11:36
// Update      		alittlexincan@163.com         	2024/07/22 11:36
// Return    		*mux.Router     				返回路由对象
func Router() *mux.Router {

	builder := NewRouteBuilder(mux.NewRouter())

	// 集成swagger文档
	builder.Swagger("/api", "./api/openapi")

	// 添加一个健康检查接口
	builder.GET("/health", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusOK)
		_, _ = w.Write([]byte("ok"))

	}))

	example := builder.Prefix("/example")
	example.Prefix("/validation").
		GET("/object", exam.SearchValidationObjectHandler()).
		GET("/attribute/transport", exam.SearchValidationAttributeTransportHandler()).
		GET("/attribute/endpoint", exam.SearchValidationAttributeEndpointHandler())

	tarot := builder.Prefix("/tarot")

	// 集群信息管理
	tarot.Prefix("/user").
		POST("", user.CreateUserHandler()).
		GET("", user.SearchUserListHandler())

	//_ = builder.baseRouter.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
	//	path, _ := route.GetPathTemplate()
	//	methods, _ := route.GetMethods()
	//	fmt.Printf("路由: %-6s %s\n", strings.Join(methods, ","), path)
	//	return nil
	//})
	return builder.baseRouter
}
